//
//  RAdaptor.cpp
//  Kmean
//
//  Created by Behrouz Derakhshan on 2/4/13.
//  Copyright (c) 2013 Behrouz. All rights reserved.
//

#include <iostream>
#include "kmean.hpp"

bool exists(std::vector<int> items,int item){
    for (int i = 0; i < items.size(); i++) {
        if(items[i] == item)
            return true;
    }
    return false;
}
extern "C"{
void test(){
    printf("HELLO");
}
}
extern "C" {
void rKmean(double* points,int* centroids,int* clusters,int* numOfDataPoints,int* dimension,int* numOfClusters){
    std::vector<Point> kmeanPoints;
    std::vector<Point> kmeanCentroids;
    for (int i = 0; i < *numOfDataPoints; i++) {
        std::vector<DATA_TYPE> temp;
        for (int j = 0; j < *dimension; j++) {
            int index = i* (*dimension) + j;
            temp.push_back(points[index]);   
        }
        Point p(temp);
        kmeanPoints.push_back(p);
    }
    for(int i = 0; i < *numOfClusters; i++){
        kmeanCentroids.push_back(kmeanPoints[centroids[i]]);
		
	}
    
    Kmean kmean(kmeanPoints,kmeanCentroids,*dimension);
    kmean.doKmean();
	kmean.printClusteredPoints();
	std::vector<int> finalClusters = kmean.getClusters();
	for (int i = 0 ; i < *numOfDataPoints;i++){
		clusters[i] = finalClusters[i];
		std::cout<<	clusters[i] << std::endl;
	}
	
}
}

